#include "nr_server_main_window.h"
#include "nr_server_device_types_widget.h"
#include "nr_server_device_type_widget.h"
#include "nr_server_device_server_widget.h"
#include "nr_server_device_group_widget.h"
#include "nr_server_device_item_widget.h"
#include "nr_server_io_manager_widget.h"
#include "nr_server_users_roles_widget.h"
#include "nr_server_users_widget.h"
#include "nr_server_user_widget.h"
#include "nr_server_roles_widget.h"
#include "nr_server_role_widget.h"
#include "nr_server_schedulers_widget.h"
#include "nr_server_scheduler_widget.h"

nr_server_main_window::nr_server_main_window(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags)
    // , m_server(this)
{
    ui.setupUi(this);
    // m_server.start();
    
   
    /* m_content_widgets.insert();
    m_content_widgets.insert();*/
}

nr_server_main_window::~nr_server_main_window()
{

}

void nr_server_main_window::init_ui()
{
    m_splitter = new QSplitter(this);
    m_splitter->setHandleWidth(5);

    m_stacked_widget = new QStackedWidget(this);
    m_device_tree = new nr_server_device_tree(this);

    m_splitter->addWidget(m_device_tree);
    m_splitter->addWidget(m_stacked_widget);

    this->setCentralWidget(m_splitter);

    int width = this->width();

    int size1 = width / 4;
    int size2 = 3 * width / 4;
    QList<int> size_list;
    size_list.append(size1);
    size_list.append(size2);
    
    m_splitter->setSizes(size_list);
}

void nr_server_main_window::init_stack_widgets()
{
    nr_server_widget_base* widget = new nr_server_device_types_widget(m_stacked_widget);
    m_content_widgets.insert(widget->type(), widget);
    
    widget = new nr_server_device_type_widget(m_stacked_widget);
    m_content_widgets.insert(widget->type(), widget);
    
    widget = new nr_server_device_server_widget(m_stacked_widget);
    m_content_widgets.insert(widget->type(), widget);
    
    widget = new nr_server_device_group_widget(m_stacked_widget);
    m_content_widgets.insert(widget->type(), widget);
        
    widget = new nr_server_device_item_widget(m_stacked_widget);
    m_content_widgets.insert(widget->type(), widget);
    
    widget = new nr_server_io_manager_widget(m_stacked_widget);
    m_content_widgets.insert(widget->type(), widget);

    widget = new nr_server_users_roles_widget(m_stacked_widget);
    m_content_widgets.insert(widget->type(), widget);

    widget = new nr_server_users_widget(m_stacked_widget);
    m_content_widgets.insert(widget->type(), widget);

    widget = new nr_server_user_widget(m_stacked_widget);
    m_content_widgets.insert(widget->type(), widget);

    widget = new nr_server_roles_widget(m_stacked_widget);
    m_content_widgets.insert(widget->type(), widget);
    
    widget = new nr_server_role_widget(m_stacked_widget);
    m_content_widgets.insert(widget->type(), widget);
    
    widget = new nr_server_schedulers_widget(m_stacked_widget);
    m_content_widgets.insert(widget->type(), widget);
    
    widget = new nr_server_scheduler_widget(m_stacked_widget);
    m_content_widgets.insert(widget->type(), widget);
}